﻿<?php
// 主页面初始化主导航菜单
$menu[]=array(
 'text'=>'首页',
 'url'=>'www.hah.com'
);
 //遍历插件目录，载入全部插件
 $pluginpath=$_SERVER['DOCUMENT_ROOT'].'/test/plugins';
 // echo $pluginpath;
 $dirH=opendir($pluginpath);
 //var_dump($dirH);  //resource(3) of type (stream)

 while($file=readdir($dirH)){
	 $pluginFilePath = $pluginpath . '/' . $file;
	  // echo $pluginFilePath;
	 // var_dump(is_file($pluginFilePath));
	 if($file != '.' && $file != '..' && is_file($pluginFilePath)){
		 include $pluginFilePath;
	 }
 }
 clearstatcache();
 //过滤出实现了IPlugin接口的插件，并执行插件注入操作。
// var_dump(get_declared_classes());  //获得php环境的所有类
// pre(get_declared_classes());
foreach(get_declared_classes() as $class){
	$reflectionClass= new ReflectionClass($class);
	if($reflectionClass->implementsInterface('Iplugin')){
		////插件初始化 
		$reflectionClass->getMethod('init')->invoke(null);
		////获取注入菜单 
		$menuIem=$reflectionClass->getMethod('getMenu')->invoke(null);
		 // var_dump($menuIem);
		$menu=array_merge($menu,array($menuIem));
	}
}
pre($menu);
